//
//  MKMainTabController.m
//  Weibo_OC
//
//  Created by mac on 16/1/11.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "MKMainTabController.h"


#import "MKHomeController.h"
#import "MKMessageController.h"
#import "MKDiscoverController.h"
#import "MKProfileController.h"
#import "MKTabBar.h"


@interface MKMainTabController ()

@end

@implementation MKMainTabController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self loadChildViewControllers];
    
    MKTabBar *mainTabBar = [[MKTabBar alloc] init];
    
    [mainTabBar.plusButton addTarget:self action:@selector(plusButtonClickEven:) forControlEvents:UIControlEventTouchUpInside];
    
    [self setValue:mainTabBar forKey:@"tabBar"];
    
    self.tabBar.tintColor = [UIColor orangeColor];
}

- (void)plusButtonClickEven:(UIButton *)sender {
    NSLog(@"++++");
}

/**
 *  加载子控制器
 */
- (void)loadChildViewControllers {

    [self loadChildViewContrller:[[MKHomeController alloc] init] andWithTitle:@"首页" andWithImageName: @"tabbar_home"];
    
    [self loadChildViewContrller:[[MKMessageController alloc] init] andWithTitle:@"消息" andWithImageName: @"tabbar_message_center"];
    
    [self loadChildViewContrller:[[MKDiscoverController alloc] init] andWithTitle:@"发现" andWithImageName: @"tabbar_discover"];
    
    [self loadChildViewContrller:[[MKProfileController alloc] init] andWithTitle:@"我" andWithImageName: @"tabbar_profile"];
    
    
}

/**
 *  设置子控制器
 *
 *  @param childVC   子控制器
 *  @param title     标题
 *  @param imageName tabBarImage 的名字
 */
- (void)loadChildViewContrller:(UIViewController *)childVC andWithTitle:(NSString *)title andWithImageName:(NSString *)imageName {
    
    NSString *selImageName = [NSString stringWithFormat:@"%@_highlighted", imageName];
    
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:childVC];
    
    childVC.tabBarItem.image = [[UIImage imageNamed: imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    childVC.tabBarItem.selectedImage = [[UIImage imageNamed: selImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    childVC.title = title;//设置标题  (nav 和tabBar 标题)
    self.tabBar.tintColor = [UIColor orangeColor];//设置tabBar选中颜色
//    childVC.view.backgroundColor = [UIColor whiteColor];
    
    [self addChildViewController:nav];
    
}




@end
